<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$this->model('member')->checkmyinfo();
	$id = intval($_RQ['id']);
	if($id){
		$params=array('id'=>$id,'uniacid'=>$_SESSION['uniacid']);
		$item=pdo_get('jy_ailiao_newslog',$params);
		$item['images']=json_decode($item['images'],true);
	}else{
		$item=array();
	}
	if($id){
		$this->session('id',$id);
	}else{
		$this->session('id',0);
	}
	$return['item']=$item;
	$return['member']=pdo_get('jy_ailiao_member',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	$return['xieyi']=$this->plugin_setting('xieyi');
	exi($return);
}
if($_RQ['op']=='post'){
	$id = $this->session('id');
	$postdata=get_postdata();
	if(!$postdata['title']){
		//exi('标题不能为空！','error');
	}
	if(!$postdata['content']){
		exi('内容不能为空！','error');
	}
	if($_SESSION['wxapp_id'] && $_SESSION['container']=='wxapp'){
			$result=model('core/wxapp_api')->msgSecCheck($postdata['content']);
			if($result['errcode']){
				exi('内容可能不合法！','error');
			}
	}
	$status = ($return['pluginset']['item_shenhe'] || $return['pluginset']['open_wxappsh'])?0:1;
	$postdata['pcd']=$postdata['pcd']?:$this->session('pcd');
	$postdata['lat_lng']=$postdata['lat_lng']?:$this->session('lat_lng');
	$data=array(
		'title'=>$postdata['title'],
		'content'=>$postdata['content'],
		'video'=>$postdata['video'],
		'thumb'=>$postdata['thumb'],
		'noshow'=>$postdata['noshow'],
		'images'=>ijson_encode($postdata['images']),
		'lat_lng'=>ijson_encode($postdata['lat_lng']),
		'pcd'=>ijson_encode($postdata['pcd']),
		'status'=>$status,
		'sex'=>$_SESSION['sex'],
	);
	if($id){
			pdo_update('jy_ailiao_newslog',$data,array('id'=>$id));
			if(!$status){
				exi('修改成功,请等待审核','','jy_ailiao/quan//type=4');
			}else{
				exi('修改成功','success','jy_ailiao/quan//type=4');
			}
	}else{
			$data['uniacid']=$_SESSION['uniacid'];
			$data['mid']=$_SESSION['uid'];
			$data['createtime']=TIMESTAMP;
			pdo_insert('jy_ailiao_newslog',$data);
			$id=pdo_insertid();
			if(intval($postdata['noshow'])){
				exi('保存预览成功！','','jy_ailiao/quan//type=4');
			}elseif(!$status){
				exi('发布成功,请等待审核','','jy_ailiao/quan//type=4');
			}else{
				exi('发布成功','','jy_ailiao/quan//type=4');
			}
			
	}
}